package com.back.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;

/**
 * 生成系统使用文件、数据库字段
 * */
public class SystemFileTool {

    private String packageOutPath = "D:/sysscfile";//指定实体生成所在包的路径
    private String packageOutPath2 = "D:/sysscfile";//指定实体生成所在包的路径
    private String packageOutPath3 = "D:/sysscfile";//指定实体生成所在包的路径
    private String packageOutPath4 = "D:/sysscfile";//指定实体生成所在包的路径


    private String authorName = "lml";//编写人
    private String tablename = "sys_user";//表名
    private String fileName = "bs_score_item";//生成文件的对应名称
    private String trueName = "评价反馈明细管理";//注释，方法的中文名称
    private String intName = "访客管理";//注释，方法的中文名称
    private String BagName = "com.ynzjxy.showroom";//包名
    private String[] colnames; // 列名数组
    private String[] colTypes; //列名类型数组
    private int[] colSizes; //列名大小数组


    //数据库连接
//	private static final String URL ="jdbc:mysql://127.0.0.1:3306/lgbdata";
//	private static final String NAME = "root";
//	private static final String PASS = "123456"; // 139.159.203.13:3306/lgbdata
    private static final String URL ="jdbc:mysql://127.0.0.1:3306/show-room-center?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai";
    private static final String NAME = "root";
    private static final String PASS = "123456";
    private static final String DRIVER ="com.mysql.cj.jdbc.Driver";

    /*
     * 构造函数
     */
    public SystemFileTool(){
        //创建连接
        Connection con;
        //查要生成实体类的表
        String sql = "SELECT * FROM " + tablename;
        PreparedStatement pStemt = null;
        try {
            try {
                Class.forName(DRIVER);
            } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
            }
            con = DriverManager.getConnection(URL,NAME,PASS);
            pStemt = con.prepareStatement(sql);
            ResultSetMetaData rsmd = pStemt.getMetaData();
            int size = rsmd.getColumnCount();   //统计列
            colnames = new String[size];
            colTypes = new String[size];
            colSizes = new int[size];
            for (int i = 0; i < size; i++) {
                colnames[i] = rsmd.getColumnName(i + 1);
                colTypes[i] = rsmd.getColumnTypeName(i + 1);
                colSizes[i] = rsmd.getColumnDisplaySize(i + 1);
            }

            //String content = parse(colnames,colTypes,colSizes);  //实体类

            //11111Mapper
            String mapperFile = mapperFile(colnames,colTypes,colSizes);

            try {
                File directory = new File("");
                //System.out.println("绝对路径："+directory.getAbsolutePath());
                //System.out.println("相对路径："+directory.getCanonicalPath());
                String path=this.getClass().getResource("").getPath();

                System.out.println(path);
                //System.out.println("src/?/"+path.substring(path.lastIndexOf("/com/", path.length())) );
                //              String outputPath = directory.getAbsolutePath()+ "/src/"+path.substring(path.lastIndexOf("/com/", path.length()), path.length()) + initcap(tablename) + ".java";
                String outputPath = this.packageOutPath.replace(".", "/")+"/" + fileName + "Dao.xml";

                //如果没有该文件时   自动创建文件
                File f = null;
                f = new File(outputPath);
                if (!f.exists()) {
                    try {
                        f.createNewFile();
                    } catch (IOException e) {
                        e.printStackTrace();
                        System.out.println("创建" + outputPath + "文件失败");
                    }
                }

                FileWriter fw = new FileWriter(outputPath);
                PrintWriter pw = new PrintWriter(fw);
                pw.println(mapperFile);

                //生成Controller
                File directory2 = new File("");
                String controllerFile = controllerFile();
                String outputPath2 = this.packageOutPath.replace(".", "/")+"/" + fileName + "Controller.java";
                //如果没有该文件时   自动创建文件
                File f2 = new File(outputPath2);
                if (!f2.exists()) {
                    try {
                        f2.createNewFile();
                    } catch (IOException e) {
                        e.printStackTrace();
                        System.out.println("创建" + outputPath2 + "文件失败");
                    }
                }
                FileWriter fw2 = new FileWriter(outputPath2);
                PrintWriter pw2 = new PrintWriter(fw2);
                pw2.println(controllerFile);
                //生成 managerFile
                File directory3 = new File("");
                String managerFile = managerFile();
                String outputPath3 = this.packageOutPath.replace(".", "/")+"/" + fileName + "Service.java";
                //如果没有该文件时   自动创建文件
                File f3 = new File(outputPath3);
                if (!f3.exists()) {
                    try {
                        f3.createNewFile();
                    } catch (IOException e) {
                        e.printStackTrace();
                        System.out.println("创建" + outputPath3 + "文件失败");
                    }
                }
                FileWriter fw3 = new FileWriter(outputPath3);
                PrintWriter pw3 = new PrintWriter(fw3);
                pw3.println(managerFile);
                //生成 ServiceImpl
                File directory4 = new File("");
                String serviceFile = serviceFile();
                String outputPath4 = this.packageOutPath.replace(".", "/")+"/" + fileName + "ServiceImpl.java";
                //如果没有该文件时   自动创建文件
                File f4 = new File(outputPath4);
                if (!f4.exists()) {
                    try {
                        f4.createNewFile();
                    } catch (IOException e) {
                        e.printStackTrace();
                        System.out.println("创建" + outputPath4 + "文件失败");
                    }
                }
                FileWriter fw4 = new FileWriter(outputPath4);
                PrintWriter pw4 = new PrintWriter(fw4);
                pw4.println(serviceFile);

                //生成 Dao
                File directory5 = new File("");
                String daoFile = daoFile();
                String outputPath5 = this.packageOutPath.replace(".", "/")+"/" + fileName + "Dao.java";
                //如果没有该文件时   自动创建文件
                File f5 = new File(outputPath5);
                if (!f5.exists()) {
                    try {
                        f5.createNewFile();
                    } catch (IOException e) {
                        e.printStackTrace();
                        System.out.println("创建" + outputPath5 + "文件失败");
                    }
                }
                FileWriter fw5 = new FileWriter(outputPath5);
                PrintWriter pw5 = new PrintWriter(fw5);
                pw5.println(daoFile);
                //生成Json文件
                File directory6 = new File("");
                String JsonFile = JsonFile();
                String outputPath6 = this.packageOutPath.replace(".", "/")+"/" + fileName + "Json.java";
                //如果没有该文件时   自动创建文件
                File f6 = new File(outputPath6);
                if (!f6.exists()) {
                    try {
                        f6.createNewFile();
                    } catch (IOException e) {
                        e.printStackTrace();
                        System.out.println("创建" + outputPath6 + "文件失败");
                    }
                }
                FileWriter fw6 = new FileWriter(outputPath6);
                PrintWriter pw6 = new PrintWriter(fw6);
                pw6.println(JsonFile);


                pw.flush();
                pw.close();

                pw2.flush();
                pw2.close();

                pw3.flush();
                pw3.close();

                pw4.flush();
                pw4.close();

                pw5.flush();
                pw5.close();

                pw6.flush();
                pw6.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally{
            //          try {
            //              con.close();
            //          } catch (SQLException e) {
            //              // TODO Auto-generated catch block
            //              e.printStackTrace();
            //          }
        }
    }

    /*生成mapper*/
    private String mapperFile(String[] colnames, String[] colTypes, int[] colSizes) {
        String returnValue = "";
        //mapper消息头
        returnValue += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">\n" +
                "<mapper namespace=\"" + BagName +".dao." + fileName +"Dao\">" + "\r\n";

        returnValue +="\r\n";
        //表名
        returnValue +="\t<!--表名-" + trueName + " -->\r\n" +
                "	<sql id=\"tableName\">\r\n" +
                "		" + tablename + "\r\n" +
                "	</sql>\r\n";


        //查询列表
        returnValue +="\t<!-- " + trueName + "列表 -->\r\n" +
                "<select id=\"getList\" parameterType=\"Map\" resultType=\"Map\">\n" +
                "    SELECT\n" +
                "    " +  processAllAttrsToMapper() +
                "       \n" +
                "    FROM\n" +
                "	<include refid=\"tableName\"></include>\r\n" +
                "   <where>\n" +
                "       <if test=\"id != null and id != ''\">\n" +
                "           AND id in (#{id})\n" +
                "       </if>\n" +
                "   </where>\n" +
                "   <if test=\"sort != null and sort != '' and sortType != null and sortType != ''\">\n" +
                "       ORDER BY ${sort} ${sortType}\n" +
                "   </if>\n" +
                "</select>\n";
        //通过条件查询获取对象获取数据
        returnValue +="\t<!-- 通过条件查询获取对象获取" + trueName + "数据 -->\r\n" +
                "<select id=\"findByCondition\" parameterType=\"Map\" resultType=\"Map\">\r\n" +
                "   SELECT \r\n" +
                "   " +  processAllAttrsToMapper() +
                "       \n" +
                "	FROM \r\n" +
                "	<include refid=\"tableName\"></include>\r\n" +
                "   <where>\n" +
                "       <if test=\"id != null and id != ''\">\n" +
                "           AND id in (#{id})\n" +
                "       </if>\n" +
                "   </where>\n" +
                "</select>\r\n";

        //新增
        returnValue +="\t<!-- 新增" + trueName + "-->\r\n" +
                "	<insert id=\"save\" parameterType=\"Map\">\r\n" +
                "		INSERT INTO \r\n" +
                "   <include refid=\"tableName\"></include>\r\n" +
                processAllAttrsToInsert() +
                "	</insert>\r\n";
        //修改
        returnValue +="\t<!-- 修改" + trueName + " -->\r\n" +
                "	<update id=\"updateById\" parameterType=\"Map\">\r\n" +
                "		UPDATE\r\n" +
                "		<include refid=\"tableName\"></include>\r\n" +
                "		SET \r\n";
        returnValue += processAllAttrsToMapperSetValue();//所有字段
        returnValue += "		WHERE \r\n" +
                "		id = #{id}\r\n" +
                "	</update>\r\n";

        //删除
        returnValue +="\t<!-- 删除 " + trueName + "-->\r\n" +
                "	<delete id=\"delete\" parameterType=\"Map\">\r\n" +
                "		DELETE FROM\r\n" +
                "		<include refid=\"tableName\"></include>\r\n" +
                "		WHERE \r\n" +
                "			id = #{id}\r\n" +
                "	</delete>\r\n";




        returnValue +="\r\n";
        returnValue +="</mapper>\r\n";

        //System.out.println(sb.toString());
        return returnValue;
    }

    /**
     * 生成Controller
     * */
    private String controllerFile() {
        String returnValue = "";
        returnValue += "package " + BagName + ".controller;\r\n";
        returnValue += "\r\n";
        //注释部分
        returnValue += "/**\r\n";
        returnValue += "    * "+fileName+" Controller\r\n";
        returnValue += "    * "+ DateUtil.getTime() +" "+this.authorName+"\r\n";
        returnValue += "*/ \r\n";

        returnValue += "import " + BagName + ".api.CommonPage;\n";
        returnValue += "import org.springframework.stereotype.Controller;\r\n";
        returnValue += "import org.springframework.beans.factory.annotation.Autowired;\r\n";
        returnValue += "import org.springframework.web.bind.annotation.*;\r\n";
        returnValue += "import " + BagName + ".api.CommonResult;\r\n";
        returnValue += "import " + BagName + ".service." + fileName + "Service;\r\n";
        returnValue += "\r\n";
        returnValue += "import java.util.List;\n";
        returnValue += "import java.util.Map;\n";

        returnValue += "\r\n";
        returnValue += "@Controller\r\n";

        returnValue += "@RequestMapping(\"/" + fileName.toLowerCase() + "\")\r\n";
        returnValue += "public class " + fileName + "Controller{\r\n";
        returnValue += "\r\n";
        returnValue += "    @Autowired \n";
        returnValue += "    private " + fileName + "Service " + toLowerCaseFirstOne(fileName) + "Service; \n";
        returnValue += "\r\n";
        returnValue += "    //查询" + trueName + "列表\r\n@RequestMapping(value = \"/getList\", method = RequestMethod.POST)\n" +
                "    @ResponseBody\n" +
                "    public CommonResult<CommonPage<Map<String, Object>>> getList(@RequestBody Map<String, Object> data) {\n" +
                "        List<Map<String, Object>> " + toLowerCaseFirstOne(fileName) + "List = " + toLowerCaseFirstOne(fileName) + "Service.getList(data);\n" +
                "        return CommonResult.success(CommonPage.restPage(" + toLowerCaseFirstOne(fileName)

                +"List));\n" +
                "    }";
        returnValue += "\r\n";
        returnValue += "    //根据条件查询" + trueName + "\r\n@RequestMapping(value = \"/findByCondition\", method = RequestMethod.POST)\n" +
                "    @ResponseBody\n" +
                "    public CommonResult<Map<String, Object>> findByCondition(@RequestBody Map<String, Object> data){\n" +
                "        return CommonResult.success(" + toLowerCaseFirstOne(fileName) + "Service.findByCondition(data));\n" +
                "    }" +
                "" +
                "";
        returnValue += "\r\n";
        returnValue += "    //新增" + trueName + "\r\n@RequestMapping(value = \"/save\", method = RequestMethod.POST)\n" +
                "    @ResponseBody\n" +
                "    public CommonResult<Map<String, Object>> insert(\n" +
                "            @RequestBody Map<String, Object> data\n" +
                "    ){\n" +
                "        return CommonResult.success(" + toLowerCaseFirstOne(fileName) + "Service.save(data));\n" +
                "    }";
        returnValue += "\r\n";
        returnValue += "    //删除" + trueName + "\r\n@RequestMapping(value = \"/delete\", method = RequestMethod.POST)\n" +
                "    @ResponseBody\n" +
                "    public CommonResult<Map<String, Object>> delete(\n" +
                "            @RequestBody Map<String, Object> data\n" +
                "    ){\n" +
                "        return CommonResult.success(" + toLowerCaseFirstOne(fileName) + "Service.delete(data));\n" +
                "    }";
        returnValue += "\r\n";
        returnValue += "    //修改" + trueName + "\r\n@RequestMapping(value = \"/updateById\", method = RequestMethod.POST)\n" +
                "    @ResponseBody\n" +
                "    public CommonResult<Map<String, Object>> updateById(\n" +
                "            @RequestBody Map<String, Object> data\n" +
                "    ){\n" +
                "        return CommonResult.success(" + toLowerCaseFirstOne(fileName) + "Service.updateById(data));\n" +
                "    }";
        returnValue += "\r\n";
        returnValue += "}";
        return returnValue;
    }

    //生成 Service
    private String managerFile() {
        String returnValue = "";
        returnValue += "package " + BagName + ".service;\r\n";
        returnValue += "\r\n";
        returnValue += "import java.util.List;\n";
        returnValue += "import java.util.Map;\n";
        returnValue += "\r\n";
        //注释部分
        returnValue += "   /**\r\n";
        returnValue += "    * "+fileName + "Service\r\n";
        returnValue += "    * "+ DateUtil.getTime() +" "+this.authorName+"\r\n";
        returnValue += "    */ \r\n";
        returnValue += "\r\n";

        returnValue += "public interface " + fileName + "Service {\r\n";
        returnValue += "\t/**获取" + trueName + "所有列表\r\n" +
                "	 */\r\n";
        returnValue += "    List<Map<String, Object>> getList(Map<String, Object> map);\r\n";
        returnValue += "\t/**\r\n" +
                "	 * 根据条件查找" + trueName + "信息\r\n" +
                "	 * */\r\n";
        returnValue += "    Map<String, Object> findByCondition(Map<String, Object> map);\r\n";
        returnValue += "\t/**新增" + trueName + "\r\n" +
                "	 */\r\n";
        returnValue += "    Map<String, Object> save(Map<String, Object> map);\r\n";
        returnValue += "\t/**修改" + trueName + "\r\n" +
                "	 */\r\n";
        returnValue += "    Map<String, Object> updateById(Map<String, Object> map);\r\n";
        returnValue += "\t/**删除" + trueName + "\r\n" +
                "	 */\r\n";
        returnValue += "    Map<String, Object> delete(Map<String, Object> map);\r\n";
        returnValue += "\r\n";
        returnValue += "}\r\n";
        return returnValue;
    }

    //生成Service
    private String serviceFile() {
        String returnValue = "";
        returnValue += "package " + BagName + ".service.impl;\r\n";
        returnValue += "\r\n";
        //注释部分
        returnValue += "   /**\r\n";
        returnValue += "    * "+fileName+"ServiceImpl\r\n";
        returnValue += "    * "+ DateUtil.getTime() +" "+this.authorName+"\r\n";
        returnValue += "    */ \r\n";

        returnValue += "import org.springframework.beans.factory.annotation.Autowired;\r\n" +
                "\r\n" +
                "import " + BagName + ".config.ConstConfig;\n" +
                "import " + BagName + ".util.DateUtil;\n" +
                "import " + BagName + ".util.UuidUtil;\n" +
                "" +
                "import org.springframework.stereotype.Service;\r\n" +
                "\r\n" +
                "import com.github.pagehelper.PageHelper;\r\n" +
                "\r\n" +
                "import java.util.HashMap;\n" +
                "import java.util.List;\r\n" +
                "import java.util.Map;\r\n" +
                "import " + BagName + ".dao." + fileName + "Dao;\n" +
                "import " + BagName + ".service." + fileName + "Service;\r\n";
        returnValue += "\r\n";
        returnValue += "@Service\r\n";
        returnValue += "public class " + fileName + "ServiceImpl implements " + fileName + "Service {\r\n";
        returnValue += "\r\n";
        returnValue += "    @Autowired\r\n" +
                "	private " + fileName + "Dao " + toLowerCaseFirstOne(fileName) + "Dao;\r\n";
        returnValue += "\r\n";
        returnValue += "\t/**" + trueName + "列表\r\n" +
                "	 */\r\n";
        returnValue += "    @Override\n" +
                "    public List<Map<String, Object>> getList(Map<String, Object> map){\n" +
                "       if( map.get(\"pageNum\") != null && map.get(\"pageSize\") != null &&\n" +
                "\t\t\t\t!map.get(\"pageNum\").toString().isEmpty() && !map.get(\"pageSize\").toString().isEmpty()){\n" +
                "\t\t\tPageHelper.startPage(Integer.parseInt(map.get(\"pageNum\").toString()) , Integer.parseInt(map.get(\"pageSize\").toString()));\n" +
                "\t\t}\n" +
                "        return " + toLowerCaseFirstOne(fileName) + "Dao.getList(map);\n" +
                "    }\n";
        returnValue += "\t/**\r\n" +
                "	 * 根据条件查找" + trueName + "信息\r\n" +
                "	 * */\r\n";
        returnValue += "    @Override\n" +
                "    public Map<String, Object> findByCondition(Map<String, Object> map){\n" +
                "       return " + toLowerCaseFirstOne(fileName) + "Dao.findByCondition(map);\n" +
                "    }\r\n";

        returnValue += "    /**\n" +
                "\t * 新增" + trueName + "\n" +
                "\t */\n" +
                "    public Map<String, Object> save(Map<String, Object> map){\n" +
                "\t\tif(map == null || map.isEmpty()\n" +
                "\t\t\t\t|| !map.containsKey(\"study_class_name\")\n" +
                "\t\t\t\t|| map.get(\"study_class_name\").toString().isEmpty()\n" +
                "\n" +
                "\t\t){\n" +
                "\t\t\tmap.put(\"rCode\", ConstConfig.FAIL_CODE_ML);\n" +
                "\t\t\tmap.put(\"rMsg\", ConstConfig.FAIL_MSG_IN_QCS);\n" +
                "\t\t}else{\n" +
                "\t\t\tMap<String, Object> map3 = new HashMap<String, Object>();\n" +
                "\t\t\tmap3.put(\"study_class_name\", map.get(\"study_class_name\").toString());\n" +
                "\n" +
                "\t\t\tMap<String, Object> map2 = " + toLowerCaseFirstOne(fileName) + "Dao.findByCondition(map3);\n" +
                "\t\t\t//查询是否存在  没有新插入  有的\n" +
                "\t\t\tif(map2 == null || map2.isEmpty()){\n" +
                "\t\t\t\tmap.put(\"id\", UuidUtil.get32UUID());\n" +
                "\t\t\t\tmap.put(\"create_time\", DateUtil.getTime());\n" +
                "\n" +
                "\t\t\t\tint types = " + toLowerCaseFirstOne(fileName) + "Dao.save(map);\n" +
                "\t\t\t\tif(types > 0){\n" +
                "\t\t\t\t\tmap.put(\"rCode\", ConstConfig.SUCCESS_CODE_ML);\n" +
                "\t\t\t\t\tmap.put(\"rMsg\", \"添加成功\");\n" +
                "\t\t\t\t}else{\n" +
                "\t\t\t\t\tmap.put(\"rCode\", ConstConfig.FAIL_CODE_ERROR);\n" +
                "\t\t\t\t\tmap.put(\"rMsg\", ConstConfig.FAIL_MSG_IN_ERROR);\n" +
                "\t\t\t\t}\n" +
                "\t\t\t}else{\n" +
                "\t\t\t\tmap.put(\"rCode\", ConstConfig.FAIL_CODE_ERROR);\n" +
                "\t\t\t\tmap.put(\"rMsg\", \"已存在相同名称的在线课堂类别\");\n" +
                "\t\t\t}\n" +
                "\t\t}\n" +
                "\t\treturn map;\n" +
                "\t}\n"+
                "\t/**\n" +
                "\t * 修改" + trueName + "\n" +
                "\t */\n" +
                "    public Map<String, Object> updateById(Map<String, Object> map){\n" +
                "\t\tif(map == null || map.isEmpty()\n" +
                "\t\t\t\t|| !map.containsKey(\"id\")\n" +
                "\t\t\t\t|| map.get(\"id\").toString().isEmpty()\n" +
                "\t\t\t\t|| !map.containsKey(\"product_num\")\n" +
                "\t\t\t\t|| map.get(\"product_num\").toString().isEmpty()\n" +
                "\t\t){\n" +
                "\t\t\tmap.put(\"rCode\", ConstConfig.FAIL_CODE_ML);\n" +
                "\t\t\tmap.put(\"rMsg\", ConstConfig.FAIL_MSG_IN_QCS);\n" +
                "\t\t}else{\n" +
                "\t\t\tint types = " + toLowerCaseFirstOne(fileName) + "Dao.updateById(map);\n" +
                "\t\t\tif(types > 0){\n" +
                "\t\t\t\tmap.put(\"rCode\", ConstConfig.SUCCESS_CODE_ML);\n" +
                "\t\t\t\tmap.put(\"rMsg\", ConstConfig.SUCCESS_MSG_UP);\n" +
                "\t\t\t}else{\n" +
                "\t\t\t\tmap.put(\"rCode\", ConstConfig.FAIL_CODE_ERROR);\n" +
                "\t\t\t\tmap.put(\"rMsg\", ConstConfig.FAIL_MSG_IN_ERROR);\n" +
                "\t\t\t}\n" +
                "\t\t}\n" +
                "\t\treturn map;\n" +
                "\n" +
                "\t}\n" +
                "\t/**\n" +
                "\t * 删除" + trueName + "\n" +
                "\t */\n" +
                "    public Map<String, Object> delete(Map<String, Object> map){\n" +
                "\t\tif(map == null || map.isEmpty()\n" +
                "\t\t\t\t|| !map.containsKey(\"id\")\n" +
                "\t\t\t\t|| map.get(\"id\").toString().isEmpty()\n" +
                "\n" +
                "\t\t){\n" +
                "\t\t\tmap.put(\"rCode\", ConstConfig.FAIL_CODE_ML);\n" +
                "\t\t\tmap.put(\"rMsg\", ConstConfig.FAIL_MSG_IN_QCS);\n" +
                "\t\t}else{\n" +
                "\t\t\tint types = " + toLowerCaseFirstOne(fileName) + "Dao.delete(map);\n" +
                "\t\t\tif(types > 0){\n" +
                "\t\t\t\tmap.put(\"rCode\", ConstConfig.SUCCESS_CODE_ML);\n" +
                "\t\t\t\tmap.put(\"rMsg\", ConstConfig.SUCCESS_MSG_DEL);\n" +
                "\t\t\t}else{\n" +
                "\t\t\t\tmap.put(\"rCode\", ConstConfig.FAIL_CODE_ERROR);\n" +
                "\t\t\t\tmap.put(\"rMsg\", ConstConfig.FAIL_MSG_IN_ERROR);\n" +
                "\t\t\t}\n" +
                "\t\t}\n" +
                "\t\treturn map;\n" +
                "\t}";
        returnValue += "\r\n";
        returnValue += "}\r\n";
        return returnValue;
    }
    /**
     * 生成Dao File
     * lml 2020-06-04
     * */
    private String daoFile(){
        String returnValue = "";
        returnValue += "package " + BagName + ".dao;\n" +
                "\n" +
                "   /**\r\n" +
                "    * "+fileName+"ServiceImpl\r\n"+
                "    * "+ DateUtil.getTime() +" "+this.authorName+"\r\n"+
                "    */ \r\n"+
                "import java.util.Map;\n" +
                "import java.util.List;\n" +
                "import org.springframework.stereotype.Repository;\n" +
                "\n" +
                "@Repository\n" +
                "public interface " + fileName + "Dao {\n" +
                "    /**\n" +
                "     * 条件查询" + trueName + "List\n" +
                "     * */\n" +
                "    List<Map<String, Object>> getList(Map<String, Object> map);\n" +
                "\n" +
                "    /**\n" +
                "     * 条件查询单个" + trueName + "\n" +
                "     * */\n" +
                "    Map<String, Object> findByCondition(Map<String, Object> map);\n" +
                "\n" +
                "    /**\n" +
                "     * 新增" + trueName + "\n" +
                "     * */\n" +
                "    int save(Map<String, Object> map);\n" +
                "\n" +
                "   /**\n" +
                "     * 修改" + trueName + "\n" +
                "     * */\n" +
                "    int updateById(Map<String, Object> map);" +
                "\n" +
                "    /**\n" +
                "     * 删除" + trueName + "\n" +
                "     * */\n" +
                "    int delete(Map<String, Object> map);\n" +
                "\n" +
                "}";
        return returnValue;
    }

    //生成Json文件
    private String JsonFile() {
        String returnValue = "";
        String titJson = "";
        String forJson = "";
        String putJson = "";
        String titlecJson = "";
        String titlesJson = "";
        for (int i = 0; i < colnames.length; i++) {
            titJson += " String " + colnames[i] + " = \"\";\n ";
            forJson += "             " + colnames[i] + " = \"\";\n" +
                    "                if(null != studentList.get(i).get(\"" + colnames[i] + "\") && !studentList.get(i).get(\""  + colnames[i]  +"\").toString().isEmpty()){\n" +
                    "                    " + colnames[i] + " = studentList.get(i).get(\"" + colnames[i] + "\").toString();\n" +
                    "                }\n";
            titlecJson += "titlec.put(\""+ colnames[i] +"\", " + colnames[i] + ");\n";
            titlesJson += "titles.put(\"11111111\", \"" + colnames[i] + "\");\n";
        }
        returnValue += titJson + "\n";
        returnValue += forJson + "\n";
        returnValue += putJson + "\n";
        returnValue += titlecJson + "\n";
        returnValue += titlesJson + "\n";

        return returnValue;
    }

    /**
     * 生成表字段
     * lml 2018-12-17
     * */
    private String processAllAttrsToMapper() {
        String allZd = "";
        String reValue = "";
        for (int i = 0; i < colnames.length; i++) {
            reValue += "\t," + colnames[i] + "\r\n";
            allZd += "," + "10275201120." + colnames[i];
        }
        allZd = allZd.substring(1);
        //System.out.println("所有字段属性=====" + allZd);
        return allZd;
    }

    /**
     * 生成新增字段
     * lml 2020-5-30
     * */
    private String processAllAttrsToInsert(){
        String reValue = "  <trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\" >\n";
        for (int i = 0; i < colnames.length; i++) {
            //System.out.print("----字段类型-----=" + colTypes[i]);
            if("VARCHAR".equals(colTypes[i]) || "varchar".equals(colTypes[i])){
                reValue +=  "       <if test=\"" + colnames[i] + " != null and " + colnames[i] + " != ''\">\n";
            }else{
                reValue += "        <if test=\"" + colnames[i] + " != null or " + colnames[i] +" == 0 \">\n";
            }
            reValue += "            " + colnames[i] + ",\r\n" +
                    "       </if>\n";
            //allZd += "10275201120." + colnames[i] + ", ";
        }
        reValue +=  "   </trim>\n" +
                "   <trim prefix=\"values (\" suffix=\")\" suffixOverrides=\",\" >\n";
        for (int i = 0; i < colnames.length; i++) {
            //System.out.print("----字段类型-----=" + colTypes[i]);
            if("VARCHAR".equals(colTypes[i].toString()) || "varchar".equals(colTypes[i].toString())){
                reValue +=  "       <if test=\"" + colnames[i] + " != null and " + colnames[i] + " != ''\">\n";
            }else{
                reValue +=  "       <if test=\"" + colnames[i] + " != null or " + colnames[i] + " == 0 \">\n";
            }
            reValue += "            #{" + colnames[i] + "},\r\n" +
                    "       </if>\n";
            //allZd += "10275201120." + colnames[i] + ", ";
        }
        reValue += "    </trim>\n";
        return reValue;
    }




    /**
     * 生成表字段的值
     * lml 2018-12-17
     * */
    private String processAllAttrsToMapperValue() {
        String retValue = "";
        for (int i = 0; i < colnames.length; i++) {
            retValue += "\t #{" + colnames[i] + "},\r\n";
        }
        return retValue;
    }

    /**
     * 更新时 set所有属性值
     * */
    private String  processAllAttrsToMapperSetValue() {
        String retValue = "";
        for (int i = 0; i < colnames.length; i++) {
            //<if test="InformationID != null and InformationID != ''">
            if("VARCHAR".equals(colTypes[i].toString()) || "varchar".equals(colTypes[i].toString())){
                retValue +=  "      <if test=\"" + colnames[i] + " != null and " + colnames[i] + " != ''\">\n";
            }else{
                retValue +=  "      <if test=\"" + colnames[i] + " != null or " + colnames[i] + " == 0 \">\n";
            }
            retValue +=
                    "          ," + colnames[i] + " = #{" + colnames[i] + "}\n" +
                            "      </if>\n";
        }
        return retValue;
    }



    /**
     166.     * 功能：将输入字符串的首字母改成大写
     167.     * @param str
     168.     * @return
     169.     */
    private String initcap(String str) {
        if(Character.isUpperCase(str.charAt(0)))
            return str;
        else
            return (new StringBuilder()).append(Character.toUpperCase(str.charAt(0))).append(str.substring(1)).toString();
    }

    //首字母转小写
    public static String toLowerCaseFirstOne(String s){
        if(Character.isLowerCase(s.charAt(0)))
            return s;
        else
            return (new StringBuilder()).append(Character.toLowerCase(s.charAt(0))).append(s.substring(1)).toString();
    }



    /**
     217.     * 出口
     218.     * TODO
     219.     * @param args
     220.     */
    public static void main(String[] args) {

        new SystemFileTool();
        System.out.println("----------运行完毕--------------");
    }



}
